package com.deft.design.decotator;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Hide丶love
 * @date 2022/05/01
 **/
@Slf4j
public class LoginSsoDecorator extends SsoDecorator {

    private static Map<String, String> AUTH_MAP = new ConcurrentHashMap<>();

    static {
        AUTH_MAP.put("huahua", "queryUserInfo");
        AUTH_MAP.put("doudou", "insertUserInfo");
    }

    public LoginSsoDecorator(HandlerInterceptor handlerInterceptor) {
        super(handlerInterceptor);
    }

    @Override
    public boolean preHandle(String request, String response, Object handler) {
        boolean success = super.preHandle(request, response, handler);
        if (!success) {
            return false;
        }
        String userId = request.substring(8);
        String method = AUTH_MAP.get(userId);
        log.info("模拟单点登录方法访问拦截校验 userId：{} method：{}", userId, method);
        return "queryUserInfo".equals(method);
    }
}
